/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.struts.service.beans;

import java.util.ArrayList;
import java.util.List;


/**
 * Class corresponding to the "formfield" of the requests_conf.xml file
 * This is the a field of the search form.
 */
public class JBFormField implements java.io.Serializable
{
    /** Form field name. */
    private String name;

    /** Kind of search, in case it is not set in the form. */
    private String type = "";

    /** List of associated business objects attributes. */
    private List beanFieldList = new ArrayList();

    /** Creates new JBFormField. */
    public JBFormField()
    {
    }

    /** Gets list of associated business objects attributes.
     * @return List of attributes names (strings).
     */
    public java.util.List getBeanFieldList()
    {
        return beanFieldList;
    }

    /**
     * Adds an associated business objects attribute.
     *
     * @param afield attribute name.
     */
    public void addBeanFieldString(String afield)
    {
        this.beanFieldList.add(afield);
    }

    /** Gets form field name.
     * @return name
     */
    public String getName()
    {
        return name;
    }

    /** Sets form field name.
     * @param aname name
     */
    public void setName(String aname)
    {
        this.name = aname;
    }

    /** Gets kind of search, in case it is not set in the form.
     * @return One of opiam.admin.faare.service.javabeans.Criteria
     * operators constant names, or empty string.
     */
    public String getType()
    {
        return type;
    }

    /** Sets kind of search, in case it is not set in the form.
     * @param atype One of opiam.admin.faare.service.javabeans.Criteria
     * operators constant names, or empty string.
     */
    public void setType(String atype)
    {
        this.type = atype;
    }

    /**
     * Displays form field definition.
     *
     * @return String formatted form field definition.
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        buf.append("         name = ");
        buf.append(name);
        buf.append(System.getProperty("line.separator"));
        buf.append("         type = ");
        buf.append(type);
        buf.append(System.getProperty("line.separator"));

        if (beanFieldList != null)
        {
            buf.append("         List components of fieldList = ");
            buf.append(System.getProperty("line.separator"));
            it = beanFieldList.iterator();

            while (it.hasNext())
            {
                buf.append("         ...");
                buf.append(it.next());
                buf.append(System.getProperty("line.separator"));
            }
        }

        return buf.toString();
    }

    // end of toString method
}
